﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class AnswerInChannelLocationRequestsController : ControllerBase
    {

        private readonly IAnswerInChannelLocationRequestAppService _app;
        public AnswerInChannelLocationRequestsController(IAnswerInChannelLocationRequestAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("answerInChannels/{answerInChannelId:Guid}/locationRequest")]
        public ActionResult<AnswerInChannelLocationRequestDto> Get([FromRoute] Guid answerInChannelId)
        {
            AnswerInChannelLocationRequestDto answerInChannelLocationRequest = _app.GetByAnswerInChannelId(answerInChannelId);
            return Ok(answerInChannelLocationRequest);
        }

        [HttpPut]
        [Route("locationRequests/{id:Guid}")]
        public ActionResult<AnswerInChannelLocationRequestDto> Put([FromRoute] Guid id, [FromBody] AnswerInChannelLocationRequestUpdateDto dto)
        {
            AnswerInChannelLocationRequestDto answerInChannelLocationRequest = _app.Update(dto);
            return Ok(answerInChannelLocationRequest);
        }

        [HttpPost]
        [Route("answerInChannels/{answerInChannelId:Guid}/locationRequest")]
        public ActionResult<AnswerInChannelLocationRequestDto> Post([FromRoute] Guid answerInChannelId, [FromBody] AnswerInChannelLocationRequestCreateDto dto)
        {
            AnswerInChannelLocationRequestDto answerInChannelLocationRequest = _app.Add(answerInChannelId, dto);
            return CreatedAtAction(nameof(Get), new { id = answerInChannelLocationRequest.Id }, answerInChannelLocationRequest);
        }

        [HttpDelete]
        [Route("locationRequests/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
